#include "tick.h"

static uint8_t tick_cnt, tick_cnt2;

void tick_init(void)
{
    tick_cnt = tick_cnt2 = 0;
}

void tick_ISR(void)
{
    g_tick_expired_10 = 1;

    if (tick_cnt == TICKS_100MS) {
        tick_cnt = 0;
        g_tick_expired_100 = 1;
    }

    if (tick_cnt2 == TICKS_1000MS) {
        g_tick_expired_500 = 1;
        g_tick_expired_1000 = 1;
        tick_cnt2 = 0;
    } else if (tick_cnt2 == TICKS_500MS) {
        g_tick_expired_500 = 1;
    }

    tick_cnt++;
    tick_cnt2++;
}
void tick_exit(void)
{
#if (CONFIG_IC_TYPE == CHIP_SS880X)
    TIMER_0_DISABLE();
    TIMER_0_INTERRUPT_DISABLE();
#elif (CONFIG_IC_TYPE == CHIP_SS881X)
    STICK_DISABLE();
    TIMER_0_INTERRUPT_DISABLE();
#endif
}

uint16_t tick_get(void)
{
    return true;
}

bool tick_timeout(uint8_t time)
{
    return (tick_cnt2 == time);
}